/**
	将认证信息注入控制器、视图中，属性名为auth
	在controller和视图中，直接this.auth访问此对象
*/
(function(){
	var Auth = Ember.Object.extend({
		user: Ember.computed(function(key, value) {
			if(arguments.length == 1){
				return {
					name: $.cookie("name"),
					role: $.cookie("role"),
					account: $.cookie("account"),
					id:$.cookie("id")
				}
			}else{
				return value;
			}
		}),

		isAdmin: Ember.computed("user.role", function() {
			return this.get("user.role") == 0;
		}),

		isNormal: Ember.computed("user.role", function() {
			return this.get("user.role") == 2;
		})
	});
	
	Ember.onLoad('Ember.Application', function(Application) {
		Application.initializer({
			name: 'injectAuth',
			initialize: function(container, application) {
				application.register('auth:apm', Auth);
				application.inject('controller', 'auth', 'auth:apm');
				application.inject('view', 'auth', 'auth:apm');
				application.inject('route', 'auth', 'auth:apm');
			}
		});
	});
})();